package rpcx

import (
	"log"
	"net"
	"net/http"
	"net/rpc"
)

//定义rpcx的类型
type ServerSayHello struct {
}

//定义传入参数类型

type RequestArgs struct {
	Name, Address string
}

func (sh *ServerSayHello) GetResponseStr(args *RequestArgs, reply *string) error {
	if args != nil {
		*reply = "Hello YourName:" + args.Name + ".YourAddress:" + args.Address
	}
	return nil
}

func Server() {
	serverSayHelloService := new(ServerSayHello) //实例化一个服务
	rpc.Register(serverSayHelloService)          //注册服务
	rpc.HandleHTTP()                             //通过http暴露的rpc消息
	l, e := net.Listen("tcp", ":1234")           //监听
	if e != nil {
		log.Fatal("listen error:", e)
	}
	http.Serve(l, nil)
}
